/**
 * 
 */
package pac1_rgr;

import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import widgets.ChooseData;
import java.awt.Rectangle;
import widgets.ChooseRandom;
import rnd.Erlang;
import rnd.Linear;
import rnd.Negexp;
import rnd.Norm;
import rnd.Uniform;

import javax.swing.JTabbedPane;
import javax.swing.JButton;
import stat.Histo;
import widgets.Diagram;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.tree.ExpandVetoException;

import process.Dispatcher;
import java.awt.Color;
import rnd.Discret;
import stat.DiscretHisto;
import java.awt.GridBagLayout;
import widgets.experiments.ExperimentControl;
import widgets.regres.RegresAnaliser;
import javax.swing.JRadioButton;
import transProcess.TransMonitorView;
import java.awt.GridBagConstraints;

/**
 * @author Administrator
 * 
 */
public class Main {

	private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu fileMenu = null;
	private JMenu editMenu = null;
	private JMenu helpMenu = null;
	private JMenuItem exitMenuItem = null;
	private JMenuItem aboutMenuItem = null;
	private JMenuItem cutMenuItem = null;
	private JMenuItem copyMenuItem = null;
	private JMenuItem pasteMenuItem = null;
	private JMenuItem saveMenuItem = null;
	private JDialog aboutDialog = null; // @jve:decl-index=0:visual-constraint="19,680"
	private JPanel aboutContentPane = null;
	private JLabel aboutVersionLabel = null;
	private ChooseData chooseDataWorkers = null;
	private ChooseData chooseDataCars = null;
	private ChooseData chooseDataPlatformSize = null;
	private ChooseData chooseDataBargeSize = null;
	private ChooseData chooseDataCarSize = null;
	private ChooseData chooseDataModelTime = null;
	private ChooseRandom chooseRandomBarge = null;
	private ChooseRandom chooseRandomWay = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel jPanelTest = null;
	private JPanel jPanelStat = null;
	private JPanel jPanelStat1 = null;
	private Histo histo = null;  //  @jve:decl-index=0:visual-constraint="536,688"
	private Diagram diagramContPort = null;
	private Diagram diagramContPlatform = null;
	private Diagram diagramQueueCars = null;
	private Diagram diagramQueueWorkers = null;
	private JButton jButtonStartTest = null;
	private Diagram diagramStat = null;
	private Diagram diagramStat1 = null;
	private JScrollPane jScrollPane = null;
	private JScrollPane jScrollPane1 = null;
	private JTextArea jTextArea = null;  //  @jve:decl-index=0:visual-constraint="382,315"
	private JTextArea jTextArea1 = null;
	private JButton jButtonStat = null;
	private JButton jButtonStat1 = null;
	private ChooseRandom chooseRandomWork = null;
	private DiscretHisto discretHisto = null; // @jve:decl-index=0:visual-constraint="410,680"
	private JPanel jPanelReg = null;
	private ExperimentControl experimentControl = null;
	private Diagram diagramReg = null;
	private RegresAnaliser regresAnaliserReg = null;
	private JRadioButton jRadioButton = null;
	private JRadioButton jRadioButton1 = null;
	private Histo histo1 = null;  //  @jve:decl-index=0:visual-constraint="601,706"
	private JPanel jPanelProc = null;
	private TransMonitorView transMonitorView = null;
	private Diagram diagram = null;
	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setBounds(new Rectangle(0, 0, 752, 655));
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("Application");
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getChooseDataWorkers(), null);
			jContentPane.add(getChooseDataCars(), null);
			jContentPane.add(getChooseDataPlatformSize(), null);
			jContentPane.add(getChooseDataBargeSize(), null);
			jContentPane.add(getChooseDataCarSize(), null);
			jContentPane.add(getChooseDataModelTime(), null);
			jContentPane.add(getChooseRandomBarge(), null);
			jContentPane.add(getChooseRandomWay(), null);
			jContentPane.add(getJTabbedPane(), null);
			jContentPane.add(getChooseRandomWork(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getFileMenu());
			jJMenuBar.add(getEditMenu());
			jJMenuBar.add(getHelpMenu());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("File");
			fileMenu.add(getSaveMenuItem());
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getEditMenu() {
		if (editMenu == null) {
			editMenu = new JMenu();
			editMenu.setText("Edit");
			editMenu.add(getCutMenuItem());
			editMenu.add(getCopyMenuItem());
			editMenu.add(getPasteMenuItem());
		}
		return editMenu;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("Help");
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("Exit");
			exitMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("About");
			aboutMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JDialog aboutDialog = getAboutDialog();
					aboutDialog.pack();
					Point loc = getJFrame().getLocation();
					loc.translate(20, 20);
					aboutDialog.setLocation(loc);
					aboutDialog.setVisible(true);
				}
			});
		}
		return aboutMenuItem;
	}

	/**
	 * This method initializes aboutDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getAboutDialog() {
		if (aboutDialog == null) {
			aboutDialog = new JDialog(getJFrame(), true);
			aboutDialog.setTitle("About");
			aboutDialog.setBounds(new Rectangle(0, 0, 300, 47));
			aboutDialog.setContentPane(getAboutContentPane());
		}
		return aboutDialog;
	}

	/**
	 * This method initializes aboutContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getAboutContentPane() {
		if (aboutContentPane == null) {
			aboutContentPane = new JPanel();
			aboutContentPane.setLayout(new BorderLayout());
			aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
		}
		return aboutContentPane;
	}

	/**
	 * This method initializes aboutVersionLabel
	 * 
	 * @return javax.swing.JLabel
	 */
	private JLabel getAboutVersionLabel() {
		if (aboutVersionLabel == null) {
			aboutVersionLabel = new JLabel();
			aboutVersionLabel
					.setText("Расчетно-графическая работа по моделированию студентов группы КИ-091 Ю.А.Ворчак, М.С.Гаценко, Л.И.Троцко вариант 9 ");
			aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutVersionLabel;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getCutMenuItem() {
		if (cutMenuItem == null) {
			cutMenuItem = new JMenuItem();
			cutMenuItem.setText("Cut");
			cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
					Event.CTRL_MASK, true));
		}
		return cutMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getCopyMenuItem() {
		if (copyMenuItem == null) {
			copyMenuItem = new JMenuItem();
			copyMenuItem.setText("Copy");
			copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
					Event.CTRL_MASK, true));
		}
		return copyMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getPasteMenuItem() {
		if (pasteMenuItem == null) {
			pasteMenuItem = new JMenuItem();
			pasteMenuItem.setText("Paste");
			pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
					Event.CTRL_MASK, true));
		}
		return pasteMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setText("Save");
			saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					Event.CTRL_MASK, true));
		}
		return saveMenuItem;
	}

	/**
	 * This method initializes chooseDataWorkers
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataWorkers() {
		if (chooseDataWorkers == null) {
			chooseDataWorkers = new ChooseData();
			chooseDataWorkers.setBounds(new Rectangle(80, 20, 200, 45));
			chooseDataWorkers.setText("40");
			chooseDataWorkers.setTitle("Кiлькiсть бригад");
			chooseDataWorkers.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					if (getJPanelTest().isShowing()) {
						getDiagramQueueWorkers().setVerticalMaxText(
								chooseDataWorkers.getText());
					}
				}
			});
		}
		return chooseDataWorkers;
	}

	/**
	 * This method initializes chooseDataCars
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataCars() {
		if (chooseDataCars == null) {
			chooseDataCars = new ChooseData();
			chooseDataCars.setBounds(new Rectangle(80, 80, 200, 45));
			chooseDataCars.setText("20");
			chooseDataCars.setTitle("Кiлькiсть автомобiлiв");
			chooseDataCars.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					if (getJPanelTest().isShowing()) {
						getDiagramQueueCars().setVerticalMaxText(
								chooseDataCars.getText());
					}
					if(getJPanelProc().isShowing()){
						getDiagram().setVerticalMaxText(
								chooseDataCars.getText());
					}
				}
			});
		}
		return chooseDataCars;
	}

	/**
	 * This method initializes chooseDataPlatformSize
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataPlatformSize() {
		if (chooseDataPlatformSize == null) {
			chooseDataPlatformSize = new ChooseData();
			chooseDataPlatformSize.setBounds(new Rectangle(80, 140, 200, 45));
			chooseDataPlatformSize.setText("200");
			chooseDataPlatformSize.setTitle("Розмiр майданчику");
			chooseDataPlatformSize.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					if (getJPanelTest().isShowing()) {
						getDiagramContPlatform().setVerticalMaxText(
								chooseDataPlatformSize.getText());
					}
				}
			});
		}
		return chooseDataPlatformSize;
	}

	/**
	 * This method initializes chooseDataBargeSize
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataBargeSize() {
		if (chooseDataBargeSize == null) {
			chooseDataBargeSize = new ChooseData();
			chooseDataBargeSize.setBounds(new Rectangle(80, 200, 200, 45));
			chooseDataBargeSize.setText("20");
			chooseDataBargeSize.setTitle("Рoзмiр баржi");
		}
		return chooseDataBargeSize;
	}

	/**
	 * This method initializes chooseDataCarSize
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataCarSize() {
		if (chooseDataCarSize == null) {
			chooseDataCarSize = new ChooseData();
			chooseDataCarSize.setBounds(new Rectangle(80, 260, 200, 45));
			chooseDataCarSize.setText("5");
			chooseDataCarSize.setTitle("Рoзмiр автомобiлю");
		}
		return chooseDataCarSize;
	}

	/**
	 * This method initializes chooseDataModelTime
	 * 
	 * @return widgets.ChooseData
	 */
	protected ChooseData getChooseDataModelTime() {
		if (chooseDataModelTime == null) {
			chooseDataModelTime = new ChooseData();
			chooseDataModelTime.setBounds(new Rectangle(80, 320, 200, 45));
			chooseDataModelTime.setText("480");
			chooseDataModelTime.setTitle("Час моделювання");
			chooseDataModelTime
					.addCaretListener(new javax.swing.event.CaretListener() {
						public void caretUpdate(javax.swing.event.CaretEvent e) {
							if (getJPanelTest().isShowing()) {
								getDiagramContPlatform().setHorizontalMaxText(
										chooseDataModelTime.getText());
								getDiagramContPort().setHorizontalMaxText(
										chooseDataModelTime.getText());
								getDiagramQueueCars().setHorizontalMaxText(
										chooseDataModelTime.getText());
								getDiagramQueueWorkers().setHorizontalMaxText(
										chooseDataModelTime.getText());
							}
						}
					});
		}
		return chooseDataModelTime;
	}

	/**
	 * This method initializes chooseRandomBarge
	 * 
	 * @return widgets.ChooseRandom
	 */
	protected ChooseRandom getChooseRandomBarge() {
		if (chooseRandomBarge == null) {
			chooseRandomBarge = new ChooseRandom();
			chooseRandomBarge.setBounds(new Rectangle(7, 446, 345, 50));
			chooseRandomBarge.setRandom(new Negexp(10));
			chooseRandomBarge
					.setTitle("Закон розподiлу часу мiж прибуттям барж");
		}
		return chooseRandomBarge;
	}

	/**
	 * This method initializes chooseRandomWay
	 * 
	 * @return widgets.ChooseRandom
	 */
	protected ChooseRandom getChooseRandomWay() {
		if (chooseRandomWay == null) {
			chooseRandomWay = new ChooseRandom();
			chooseRandomWay.setBounds(new Rectangle(7, 505, 346, 50));
			chooseRandomWay.setTitle("Закон розподiлу часу роботи автомобiлю");
			chooseRandomWay.setRandom(new Uniform(0.5,2));
		}
		return chooseRandomWay;
	}

	/**
	 * This method initializes jTabbedPane
	 * 
	 * @return javax.swing.JTabbedPane
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setBounds(new Rectangle(360, 5, 375, 585));
			jTabbedPane.setToolTipText("");
			jTabbedPane.setName("");
			jTabbedPane.addTab("Тест моделi", null, getJPanelTest(), null);
			jTabbedPane.addTab("Статистика(1)", null, getJPanelStat(), null);
			jTabbedPane.addTab("Статистика(2)", null, getJPanelStat1(), null);
			jTabbedPane.addTab("Регресивний", null, getJPanelReg(), null);
			jTabbedPane.addTab("Перехідний процес", null, getJPanelProc(), null);
			
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes jPanelTest
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelTest() {
		if (jPanelTest == null) {
			jPanelTest = new JPanel();
			jPanelTest.setLayout(null);
			jPanelTest.add(getDiagramContPort(), null);
			jPanelTest.add(getDiagramContPlatform(), null);
			jPanelTest.add(getDiagramQueueCars(), null);
			jPanelTest.add(getDiagramQueueWorkers(), null);
			jPanelTest.add(getJButtonStartTest(), null);
		}
		return jPanelTest;
	}

	/**
	 * This method initializes jPanelStat
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelStat() {
		if (jPanelStat == null) {
			jPanelStat = new JPanel();
			jPanelStat.setLayout(null);
			jPanelStat.add(getDiagramStat(), null);
			jPanelStat.add(getJScrollPane(), null);
			jPanelStat.add(getJButtonStat(), null);
		}
		return jPanelStat;
	}
	
	/**
	 * This method initializes jPanelStat
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelStat1() {
		if (jPanelStat1 == null) {
			jPanelStat1 = new JPanel();
			jPanelStat1.setLayout(null);
			jPanelStat1.add(getDiagramStat1(), null);
			jPanelStat1.add(getJScrollPane1(), null);
			jPanelStat1.add(getJButtonStat1(), null);
		}
		return jPanelStat1;
	}
	
	/**
	 * This method initializes histo
	 * 
	 * @return stat.Histo
	 */
	protected Histo getHisto() {
		if (histo == null) {
			histo = new Histo();
		}
		return histo;
	}

	/**
	 * This method initializes diagramContPort
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramContPort() {
		if (diagramContPort == null) {
			diagramContPort = new Diagram();
			diagramContPort.setBounds(new Rectangle(5, 5, 360, 120));
			diagramContPort.setPainterColor(Color.magenta);
			diagramContPort.setPanelBackground(Color.cyan);
			diagramContPort.setHorizontalMaxText("480");
			diagramContPort.setVerticalMaxText("300");
			diagramContPort.setTitleText("Черга контейнерiв у порту");
		}
		return diagramContPort;
	}

	/**
	 * This method initializes diagramContPlatform
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramContPlatform() {
		if (diagramContPlatform == null) {
			diagramContPlatform = new Diagram();
			diagramContPlatform.setBounds(new Rectangle(5, 130, 360, 120));
			diagramContPlatform.setVerticalMaxText("200");
			diagramContPlatform.setPainterColor(Color.magenta);
			diagramContPlatform.setPanelBackground(Color.cyan);
			diagramContPlatform.setHorizontalMaxText("480");
			diagramContPlatform.setTitleText("Черга контейнерiв на майданчику");
		}
		return diagramContPlatform;
	}

	/**
	 * This method initializes diagramQueueCars
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramQueueCars() {
		if (diagramQueueCars == null) {
			diagramQueueCars = new Diagram();
			diagramQueueCars.setBounds(new Rectangle(5, 255, 360, 120));
			diagramQueueCars.setVerticalMaxText("20");
			diagramQueueCars.setPanelBackground(Color.cyan);
			diagramQueueCars.setPainterColor(Color.blue);
			diagramQueueCars.setHorizontalMaxText("480");
			diagramQueueCars.setTitleText("Черга автомобiлiв");
		}
		return diagramQueueCars;
	}

	/**
	 * This method initializes diagramQueueWorkers
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramQueueWorkers() {
		if (diagramQueueWorkers == null) {
			diagramQueueWorkers = new Diagram();
			diagramQueueWorkers.setBounds(new Rectangle(5, 380, 360, 120));
			diagramQueueWorkers.setTitleText("Черга бригад");
			diagramQueueWorkers.setPainterColor(Color.blue);
			diagramQueueWorkers.setPanelBackground(Color.cyan);
			diagramQueueWorkers.setHorizontalMaxText("480");
			diagramQueueWorkers.setVerticalMaxText("40");
		}
		return diagramQueueWorkers;
	}

	/**
	 * This method initializes jButtonStartTest
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonStartTest() {
		if (jButtonStartTest == null) {
			jButtonStartTest = new JButton();
			jButtonStartTest.setBounds(new Rectangle(100, 505, 175, 25));
			jButtonStartTest.setText("Почати тест");
			jButtonStartTest
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							startTest();
						}
					});
		}
		return jButtonStartTest;
	}

	/**
	 * This method initializes diagramStat
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramStat() {
		if (diagramStat == null) {
			diagramStat = new Diagram();
			diagramStat.setBounds(new Rectangle(5, 10, 360, 230));
			diagramStat.setVerticalMaxText("1");
			diagramStat.setTitleText("Гiстограма для черги контейнерiв на майданчику");
			diagramStat.setHorizontalMaxText("48");
			diagramStat.setBackground(Color.cyan);
		}
		return diagramStat;
	}
	
	/**
	 * This method initializes diagramStat
	 * 
	 * @return widgets.Diagram
	 */
	protected Diagram getDiagramStat1() {
		if (diagramStat1 == null) {
			diagramStat1 = new Diagram();
			diagramStat1.setBounds(new Rectangle(5, 10, 360, 230));
			diagramStat1.setVerticalMaxText("1");
			diagramStat1.setTitleText("Гiстограма для часу доставки контейнерiв");
			diagramStat1.setHorizontalMaxText("48");
			diagramStat1.setBackground(Color.cyan);
		}
		return diagramStat1;
	}
	
	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(5, 260, 360, 240));
			jScrollPane.setViewportView(getJTextArea());
		}
		return jScrollPane;
	}
	/**
	 * This method initializes jScrollPane1
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBounds(new Rectangle(5, 260, 360, 240));
			jScrollPane1.setViewportView(getJTextArea1());
		}
		return jScrollPane1;
	}

	/**
	 * This method initializes jTextArea
	 * 
	 * @return javax.swing.JTextArea
	 */
	protected JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
		}
		return jTextArea;
	}

	/**
	 * This method initializes jTextArea1
	 * 
	 * @return javax.swing.JTextArea
	 */
	protected JTextArea getJTextArea1() {
		if (jTextArea1 == null) {
			jTextArea1 = new JTextArea();
		}
		return jTextArea1;
	}

	/**
	 * This method initializes jButtonStat
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonStat() {
		if (jButtonStat == null) {
			jButtonStat = new JButton();
			jButtonStat.setBounds(new Rectangle(100, 505, 175, 25));
			jButtonStat.setText("Почати експеримент");
			jButtonStat.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					startStat();
				}
			});
		}
		return jButtonStat;
	}
	/**
	 * This method initializes jButtonStat1
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonStat1() {
		if (jButtonStat1 == null) {
			jButtonStat1 = new JButton();
			jButtonStat1.setBounds(new Rectangle(100, 505, 175, 25));
			jButtonStat1.setText("Почати експеримент");
			jButtonStat1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					startStat1();
				}
			});
		}
		return jButtonStat1;
	}

	/**
	 * This method initializes chooseRandomWork
	 * 
	 * @return widgets.ChooseRandom
	 */
	protected ChooseRandom getChooseRandomWork() {
		if (chooseRandomWork == null) {
			chooseRandomWork = new ChooseRandom();
			chooseRandomWork.setBounds(new Rectangle(7, 385, 346, 50));
			chooseRandomWork.setTitle("Закон розподiлу часу розвантаження баржi");
			chooseRandomWork.setRandom(new Uniform(0.1,0.2));
		}
		return chooseRandomWork;
	}

	/**
	 * This method initializes discretHisto
	 * 
	 * @return stat.DiscretHisto
	 */
	protected DiscretHisto getDiscretHisto() {
		if (discretHisto == null) {
			discretHisto = new DiscretHisto();
		}
		return discretHisto;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */


	/**
	 * This method initializes jPanelReg	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelReg() {
		if (jPanelReg == null) {
			jPanelReg = new JPanel();
			jPanelReg.setLayout(null);
			jPanelReg.add(getExperimentControl(), null);
			jPanelReg.add(getDiagramReg(), null);
			jPanelReg.add(getRegresAnaliserReg(), null);
			jPanelReg.add(getJRadioButton(), null);
			jPanelReg.add(getJRadioButton1(), null);
		}
		return jPanelReg;
	}

	/**
	 * This method initializes experimentControl	
	 * 	
	 * @return widgets.experiments.ExperimentControl	
	 */
	private ExperimentControl getExperimentControl() {
		if (experimentControl == null) {
			experimentControl = new ExperimentControl();
			experimentControl.setBounds(new Rectangle(-1, 1, 370, 121));
			experimentControl.setTextFactors("2 5 10 15 20");
			experimentControl.setTextTestTime("200");
			experimentControl.setTextNExpr("10");
			experimentControl.setDiagram(getDiagramReg());
			experimentControl.setFactory(new FactoryForRgrModel(this));
		}
		return experimentControl;
	}

	/**
	 * This method initializes diagramReg	
	 * 	
	 * @return widgets.Diagram	
	 */
	private Diagram getDiagramReg() {
		if (diagramReg == null) {
			diagramReg = new Diagram();
			diagramReg.setBounds(new Rectangle(3, 121, 364, 184));
			diagramReg.setTitleText("Середнє зн-ня черги від к-ті машин");
			diagramReg.setHorizontalMaxText("21");
			diagramReg.setVerticalMaxText("120");
			diagramReg.setVerticalMinText("-1");
			diagramReg.setHorizontalMinText("-1");
			diagramReg.setBackground(Color.cyan);
		}
		return diagramReg;
	}

	/**
	 * This method initializes regresAnaliserReg	
	 * 	
	 * @return widgets.regres.RegresAnaliser	
	 */
	private RegresAnaliser getRegresAnaliserReg() {
		if (regresAnaliserReg == null) {
			regresAnaliserReg = new RegresAnaliser();
			regresAnaliserReg.setBounds(new Rectangle(1, 305, 367, 174));
			regresAnaliserReg.setExperimentControl(getExperimentControl());
			regresAnaliserReg.setDiagram(getDiagramReg());
		}
		return regresAnaliserReg;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setBounds(new Rectangle(15, 481, 333, 21));
			jRadioButton.setText("Среднє значення черги барж у порту");
			jRadioButton.setMnemonic(KeyEvent.VK_UNDEFINED);
			jRadioButton.setName("AverageQueue");
			jRadioButton.setToolTipText("");
			jRadioButton.setActionCommand("Среднє значення черги барж у порту");
			jRadioButton.setSelected(true);
			jRadioButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton.isSelected()){
						getDiagramReg().setTitleText("Середнє зн-ня черги барж у порту від к-ті машин");
						jRadioButton1.setSelected(false);
					}
				}
			});
			
		}
		return jRadioButton;
	}

	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setBounds(new Rectangle(16, 504, 347, 21));
			jRadioButton1.setActionCommand("Час очiкування доставки контейнерiв");
			jRadioButton1.setText("Час очiкування доставки контейнерiв");
			jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton1.isSelected()){
						getDiagramReg().setTitleText("Час очiкування доставки контейнерiв від к-ті авто");
						jRadioButton.setSelected(false);
					}
				}
			});
		}
		return jRadioButton1;
	}

	/**
	 * This method initializes histo1	
	 * 	
	 * @return stat.Histo	
	 */
	public Histo getHisto1() {
		if (histo1 == null) {
			histo1 = new Histo();
		}
		return histo1;
	}

	/**
	 * This method initializes jPanelProc	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelProc() {
		if (jPanelProc == null) {
			jPanelProc = new JPanel();
			jPanelProc.setLayout(null);
			jPanelProc.setToolTipText("");
			jPanelProc.setName("");
			jPanelProc.add(getTransMonitorView(), null);
			jPanelProc.add(getDiagram(), null);
			jPanelProc.addComponentListener(new java.awt.event.ComponentAdapter() {
				public void componentShown(java.awt.event.ComponentEvent e) {
					getDiagram().setVerticalMaxText(
							chooseDataCars.getText());
				}
			});
		}
		return jPanelProc;
	}

	/**
	 * This method initializes transMonitorView	
	 * 	
	 * @return transProcess.TransMonitorView	
	 */
	private TransMonitorView getTransMonitorView() {
		if (transMonitorView == null) {
			transMonitorView = new TransMonitorView();
			transMonitorView.setBounds(new Rectangle(108, 9, 164, 216));
			transMonitorView.setFactory(new FactoryForRgrModel(this));
			transMonitorView.setПараллельно_моделей("70");
			transMonitorView.setDiagram(getDiagram());
		}
		return transMonitorView;
	}

	/**
	 * This method initializes diagram	
	 * 	
	 * @return widgets.Diagram	
	 */
	private Diagram getDiagram() {
		if (diagram == null) {
			diagram = new Diagram();
			diagram.setBounds(new Rectangle(11, 236, 346, 236));
			diagram.setGridColor(Color.darkGray);
			diagram.setPainterColor(Color.blue);
			diagram.setBackground(Color.cyan);
			diagram.setTitleText("Середнє значення черги автомобілів");
		}
		return diagram;
	}

	/**
	 * Launches this application
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Main application = new Main();
				application.getJFrame().setVisible(true);
			}
		});
	}

	private void startTest() {
		getDiagramContPort().clear();
		getDiagramContPlatform().clear();
		getDiagramQueueCars().clear();
		getDiagramQueueWorkers().clear();
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		Model model = factory.createModel(dispatcher);
		model.initForTest();
		dispatcher.start();
		getJButtonStartTest().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера,
		// а після цього відновлює доступність кнопки "Старт"
		new Thread() {
			public void run() {
				// Затримка до кінця моделювання
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStartTest().setEnabled(true);
			}
		}.start();
	}

	public void startStat() {
		getDiagramStat().clear();
		getJTextArea().setText("");
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		final Model model = factory.createModel(dispatcher);
		model.initForStat();
		dispatcher.start();
		getJButtonStat().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера
		// а після цього відновлює доступність кнопки "Почати експеримент"
		// та виводить на екран статистичні характеристики черги
		new Thread() {
			public void run() {
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStat().setEnabled(true);
				getDiscretHisto().showRelFrec(getDiagramStat());
				getJTextArea().setText(getDiscretHisto().toString());
				getJTextArea().select(0, 0);
			}
		}.start();

	}
	
	public void startStat1() {
		getDiagramStat1().clear();
		getJTextArea1().setText("");
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		final Model model = factory.createModel(dispatcher);
		model.initForStat();
		dispatcher.start();
		getJButtonStat1().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера
		// а після цього відновлює доступність кнопки "Почати експеримент"
		// та виводить на екран статистичні характеристики черги
		new Thread() {
			public void run() {
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStat1().setEnabled(true);
				getHisto1().showRelFrec(getDiagramStat1());
				getJTextArea1().setText(getHisto1().toString());
				getJTextArea1().select(0, 0);
			}
		}.start();

	}
}
